package com.bl.weilan.api.controller.company;

import com.bl.weilan.api.controller.BaseController;
import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.CompanyEntity;
import com.bl.weilan.service.biz.company.CompanyService;
import com.bl.weilan.service.biz.search.SearchService;
import com.bl.weilan.service.vo.company.CompanyListVo;
import com.bl.weilan.service.vo.company.CompanyOnlyListVo;
import com.bl.weilan.service.vo.company.CompanyVo;
import com.bl.weilan.service.vo.institution.InstitutionListVo;
import com.bl.weilan.service.vo.news.NewsListVo;
import com.bl.weilan.service.vo.report.ReportListVo;
import com.bl.weilan.service.vo.search.SearchListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/apis/company"})
@Api(value = "公司相关", description = "公司相关api")
public class CompanyController  extends BaseController {

    @Autowired
    CompanyService companyService;

    @Autowired
    SearchService searchService;


    @ApiOperation(value = "通过 tradeId 和 tradeType 获取公司列表,排序类型：foundTime-创建时间 valuations-估值 point-综合评分 升序-asc 降序-desc", notes = "获取公司列表，排序类型：time-创建时间 value-估值 point-综合评分 升序-asc 降序-desc")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tradeId", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "tradeType", value = "行业分类，TRADEB TRADE TRADEB", required = false, paramType = "query", dataType = "int", defaultValue = ""),
            @ApiImplicitParam(name = "type", value = "排序类型", required = true, paramType = "query", dataType = "String", defaultValue = "time"),
            @ApiImplicitParam(name = "order", value = "升序/降序", required = true, paramType = "query", dataType = "String", defaultValue = "desc"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<CompanyListVo> companyList(
            @RequestParam(value = "tradeId", required = true, defaultValue = "1") String tradeId,
            @RequestParam(value = "tradeType", required = true, defaultValue = "1") String tradeType,
            @RequestParam(value = "type", required = false, defaultValue = "time") String type,
            @RequestParam(value = "order", required = false, defaultValue = "desc") String order,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        CompanyListVo companyListVo = companyService.getCompanyListsByTrade(tradeId, tradeType, type, order, pageable);

        return ApiResponseBody.createSuccessBody(companyListVo);
    }

    @ApiOperation(value = "获取一条公司详情信息", notes = "获取一条公司")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_detail"})
    public ApiResponseBody<CompanyListVo> companyList(
            @RequestParam(value = "id", required = true) String id,
            HttpServletRequest request) {

        CompanyVo companyVo = companyService.getCompanyById(id);

        return ApiResponseBody.createSuccessBody(companyVo);
    }

    @ApiOperation(value = "搜索公司", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "str", value = "str", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/search_company"})
    public ApiResponseBody<CompanyOnlyListVo> searchCompany(
            @RequestParam(value = "str", required = true) String str,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {
        Pageable pageable = new PageRequest(page - 1, size);

        CompanyOnlyListVo searchListVo = searchService.searchCompanyEntityEntityByName(str, pageable);

        return ApiResponseBody.createSuccessBody(searchListVo);
    }

    @ApiOperation(value = "搜索新闻", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "str", value = "str", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/search_news"})
    public ApiResponseBody<NewsListVo> searchNews(
            @RequestParam(value = "str", required = true) String str,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {
        Pageable pageable = new PageRequest(page - 1, size);

        NewsListVo searchListVo = searchService.searchNewsEntityByName(str, pageable);

        return ApiResponseBody.createSuccessBody(searchListVo);
    }

    @ApiOperation(value = "搜索报告", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "str", value = "str", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/search_report"})
    public ApiResponseBody<ReportListVo> searchReport(
            @RequestParam(value = "str", required = true) String str,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {
        Pageable pageable = new PageRequest(page - 1, size);

        ReportListVo searchListVo = searchService.searchReportEntityByName(str, pageable);

        return ApiResponseBody.createSuccessBody(searchListVo);
    }

    @ApiOperation(value = "搜索机构功能", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "str", value = "str", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/search_institution"})
    public ApiResponseBody<InstitutionListVo> searchInstitution(
            @RequestParam(value = "str", required = true) String str,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {
        Pageable pageable = new PageRequest(page - 1, size);

        InstitutionListVo searchListVo = searchService.searchInstitutionEntityByName(str, pageable);

        return ApiResponseBody.createSuccessBody(searchListVo);
    }


}
